//
//  RWGoodsSPECViewController.m
//  RedWine
//
//  Created by Liufangfang on 2017/1/10.
//  Copyright © 2017年 HuiBangKe. All rights reserved.
//

#import "RWGoodsSPECViewController.h"
#import "RWGoodsDetailModel.h"

@interface RWGoodsSPECViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *goodsSPECTV;
@property (nonatomic, copy) NSMutableArray *attNames;
@property (nonatomic, copy) NSMutableArray *values;

@end

@implementation RWGoodsSPECViewController

#pragma mark - View LifeCycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setGoodsSPECUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Load Datas

- (void)loadDataWithSPECs:(NSArray *)specs{

    _attNames = [NSMutableArray array];
    _values = [NSMutableArray array];
    
    for (NSDictionary *spec in specs) {
        
        RWGoodsDetailSPECModel *specModel = [RWGoodsDetailSPECModel mj_objectWithKeyValues:spec];
        [_attNames addObject:specModel.name];
        [_values addObject:specModel.value];
    }
}

#pragma mark - Config UI

- (void)setGoodsSPECUI{
   
    _goodsSPECTV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-(64+41)*FTY_HEIGHT_BASE) style:UITableViewStylePlain];
    [self.view addSubview:_goodsSPECTV];
    _goodsSPECTV.separatorStyle = UITableViewCellSeparatorStyleNone;
    _goodsSPECTV.delegate = self;
    _goodsSPECTV.dataSource = self;
    _goodsSPECTV.rowHeight = 44;
}

#pragma mark - Config Invoke Methods

#pragma mark - Notification Method

#pragma mark - Notification Invoke Methods

#pragma mark - <UITableViewDataSource>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return _attNames.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 40.*FTY_HEIGHT_BASE;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString * const specID = @"specID";
    UITableViewCell *specCell = [tableView dequeueReusableCellWithIdentifier:specID];
    NSInteger row = indexPath.row;
    
    if (!specCell) {
        
        specCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:specID];
        specCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UILabel *attNameLab = [[UILabel alloc] init];
        [specCell addSubview:attNameLab];
        attNameLab.text = _attNames[row];
        attNameLab.textColor = [UIColor blackColor];
        attNameLab.font = FTY_FONTTSIZE(15);
        [attNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(specCell.mas_centerY);
            make.left.mas_equalTo(10.*FTY_WIDTH_BASE);
            make.width.mas_equalTo(80.*FTY_WIDTH_BASE);
        }];
        
        UILabel *valueLab = [[UILabel alloc] init];
        [specCell addSubview:valueLab];
        valueLab.text = _values[row];
        valueLab.textColor = [UIColor blackColor];
        valueLab.font = FTY_FONTTSIZE(15);
        [valueLab sizeToFit];
        [valueLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(specCell.mas_centerY);
            make.left.mas_equalTo(attNameLab.mas_right).offset(15.*FTY_WIDTH_BASE);
            make.right.mas_equalTo(-10.*FTY_WIDTH_BASE);
        }];
        
        //底部线
        UIView *line = [[UIView alloc] init];
        [specCell addSubview:line];
        line.backgroundColor = [UIColor grayColor];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.mas_offset(0);
            make.height.mas_offset(.5*FTY_HEIGHT_BASE);
        }];
    }
    
    return specCell;
}

#pragma mark - <UITableViewDelegate>

#pragma mark - Private Invoke Methods

@end
